package cn.technology.forum.dto;

/**
 * @author moguai
 * @version 1.0
 * @date 2022/4/10 16:39
 */

import cn.technology.forum.util.ReturnMsgUtil;

import java.util.HashMap;
import java.util.Map;


public class R extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public R() {
        put("code", ReturnMsgUtil.SUCCESS_CODE);
        put("msg", ReturnMsgUtil.SUCCESS_MSG);
    }

    public static R error() {
        return error(ReturnMsgUtil.ERROR_CODE, ReturnMsgUtil.ERROR_MSG);
    }

    public static R errorServe() {
        return error(ReturnMsgUtil.SERVER_ERROR_CODE, ReturnMsgUtil.SERVER_ERROR_MSG);
    }

    public static R errorMethod() {
        return error(ReturnMsgUtil.SERVER_METHOD_ERROR_CODE, ReturnMsgUtil.SERVER_METHOD_ERROR_MSG);
    }

    public static R errorMobile() {
        return error(ReturnMsgUtil.MOBILE_REPEAT, ReturnMsgUtil.MOBILE_REPEAT_INFO);
    }

    public static R errorUser() {
        return error(ReturnMsgUtil.NOT_USER_NAME, ReturnMsgUtil.NOT_USER_NAME_INFO);
    }

    public static R errorPwd() {
        return error(ReturnMsgUtil.PASSWORD_ERROR, ReturnMsgUtil.PASSWORD_ERROR_INFO);
    }

    public static R userError() {
        return error(ReturnMsgUtil.USER_ERROR, ReturnMsgUtil.USER_ERROR_INFO);
    }

    public static R expiredVerifyCode() {
        return error(ReturnMsgUtil.VERIFYCODE_EXPIRED, ReturnMsgUtil.VERIFYCODE_EXPIRED_INFO);
    }

    public static R errorVerifyCode() {
        return error(ReturnMsgUtil.VERIFYCODE_ERROR, ReturnMsgUtil.VERIFYCODE_ERROR_INFO);
    }

    public static R expiredOldVerifyCode() {
        return error(ReturnMsgUtil.OLD_VERIFYCODE_EXPIRED, ReturnMsgUtil.OLD_VERIFYCODE_EXPIRED_INFO);
    }

    public static R errorOldVerifyCode() {
        return error(ReturnMsgUtil.OLD_VERIFYCODE_ERROR, ReturnMsgUtil.OLD_VERIFYCODE_ERROR_INFO);
    }

    public static R errorParameter() {
        return error(ReturnMsgUtil.PARAMETER_ERROR, ReturnMsgUtil.PARAMETER_ERROR_INFO);
    }

    public static R errorOldPwd() {
        return error(ReturnMsgUtil.OLD_PWD_ERROR, ReturnMsgUtil.OLD_PWD_ERROR_INFO);
    }

    public static R errorGraphicVerity() {
        return error(ReturnMsgUtil.GRAPHIC_VERIFICATION_ERROR, ReturnMsgUtil.GRAPHIC_VERIFICATION_ERROR_INFO);
    }

    public static R error(String msg) {
        return error(500, msg);
    }

    public static R error(int code, String msg) {
        R r = new R();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }

    public static R ok(String msg) {
        R r = new R();
        r.put("msg", msg);
        return r;
    }

    public static R ok(Object list, long total) {
        R r = new R();
        r.put("list", list);
        r.put("total", total);
        return r;
    }

    public static R correct(Object data, long count) {
        R r = new R();
        r.put("data", data);
        r.put("count", count);
        return r;
    }

    public static R ok(Object list, long total,long totalPage,long currPage) {
        R r = new R();
        r.put("list", list);
        r.put("total", total);
        r.put("totalPage", totalPage);
        r.put("currPage", currPage);
        return r;
    }

    public static R ok(Object list, long currPage, long pageSize, long totalPage, long total) {
        R r = new R();
        r.put("data", list);
        r.put("currPage", currPage);
        r.put("pageSize", pageSize);
        r.put("totalPage", totalPage);
        r.put("total", total);
        return r;
    }

/*  public static R ok(PageInfo<?> page) {
    R r = new R();
    r.put("count", page.getTotal());
    r.put("data", page.getList());
    return r;
  }*/

    public static R ok(Map<String, Object> map) {
        R r = new R();
        r.putAll(map);
        return r;
    }

    public static R ok(Object obj) {
        R r = new R();
        r.put("data",obj);
        return r;
    }

    public static R ok() {
        return new R();
    }

    @Override
    public R put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
